﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class rizhiControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        CustomGridView CustomGridList1;
        DropDownList 事件名称;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            事件名称 = (DropDownList)FindControl("事件名称");
            if (base.Page.Request["action"] != null && base.Page.Request["action"].ToString() == "del" && base.Page.Request["id"] != null)
            {
                bool del = _EluZSDataProvider.DeleteXmByID("zs_rizhi", "id", base.Page.Request["id"]);
                if (del) { base.Page.Response.Redirect("rizhi.aspx"); }
            }
            if (!base.Page.IsPostBack)
            {
                BindType();
                Bind();
            }
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
            Button gotosearch = (Button)FindControl("gotosearch");
            gotosearch.Click += new EventHandler(Go_Search);
        }
        protected void Go_Search(object sender, EventArgs e)
        {
            Bind();
        }
        protected void BindType() {
            DataTable dt = _EluZSDataProvider.GetRiZhi("0", "");
            if (dt != null)
            {
                事件名称.Items.Add(new ListItem(""));
                for (int temp = 0; temp < dt.Rows.Count; temp++)
                {
                    ListItem item = new ListItem(dt.Rows[temp]["EVENTNAME"].ToString());
                    事件名称.Items.Add(item);
                }
            }
        }
        protected void Bind()
        {
            CustomGridList1.RowDataBound += new GridViewRowEventHandler(CustomGridList1_RowDataBound);
            DataTable dt = _EluZSDataProvider.GetRiZhi("1", GetSqlWhere());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataKeyNames = new string[] { "ID" };
            CustomGridList1.DataBind();
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected string GetSqlWhere() {
            string sqlWhere = string.Empty;
            if (!string.IsNullOrEmpty(事件名称.SelectedValue))
            {
                sqlWhere = " and EVENTNAME='" + 事件名称.SelectedValue + "' ";
            }
            return sqlWhere;
        }
        protected void CustomGridList1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dr = (DataRowView)e.Row.DataItem;
                if (dr != null)
                {
                    Label delrizhi = (Label)e.Row.FindControl("delrizhi");
                    if (_EluZSDataProvider.IsNetZSAdmin(userid) || _EluZSDataProvider.IsZSAdmin(userid))
                    {
                        delrizhi.Visible = true;
                    }
                }
            }
        }
    }
}


